#! /bin/sh
# 
# Laptop mode tools module: Runtime Power Management
#


activate_runtime_suspend() {
	for device in $1/*; do
		if [ -f $device/power/control ]; then
			echo "auto" > $device/power/control;
			log "VERBOSE" "Setting Runtime PM auto for device $device"
		else
			log "VERBOSE" "$device does not support Runtime PM"
		fi
	done

}

if [ x$CONTROL_RUNTIME_PM = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_RUNTIME_PM = xauto ]; then
	log "VERBOSE" "Activating Runtime PM for device type PCI"
	activate_runtime_suspend "/sys/bus/pci/devices"

	log "VERBOSE" "Activating Runtime PM for device type SPI"
	activate_runtime_suspend "/sys/bus/spi/devices"

	log "VERBOSE" "Activating Runtime PM for device type i2c"
	activate_runtime_suspend "/sys/bus/i2c/devices"
else
	log "VERBOSE" "Linux Runtime PM disabled."
fi
